from core.base.page_base import BasePage
from selenium.webdriver.common.by import By


class RegisterPage(BasePage):
    # 定位器字典：键为属性名，值为(By定位方式, 定位表达式)
    locators = {
        "username_input": (By.ID, "reg_username"),  # 注册用户名输入框
        "email_input": (By.ID, "reg_email"),        # 邮箱输入框
        "password_input": (By.ID, "reg_password"),  # 密码输入框
        "confirm_btn": (By.CSS_SELECTOR, "#reg_form .submit-btn"),  # 确认注册按钮
        "success_msg": (By.CLASS_NAME, "reg_success"),  # 注册成功提示
        "error_msg": (By.CLASS_NAME, "reg_error")       # 注册失败提示
    }

    def do_register(self, username, email, password):
        """业务方法：执行注册操作"""
        self.username_input = username  # 输入用户名（触发描述符__set__）
        self.email_input = email        # 输入邮箱
        self.password_input = password  # 输入密码
        self.confirm_btn.click()        # 点击注册按钮（触发描述符__get__）

    def get_register_result(self):
        """业务方法：获取注册结果提示（成功/失败）"""
        try:
            # 优先检查成功提示
            return self.success_msg.text
        except:
            # 失败时返回错误提示
            return self.error_msg.text